package com.xw.childhealth.controller;

import com.xw.childhealth.VO.ResultVO;
import com.xw.childhealth.entity.XzCode;
import com.xw.childhealth.service.XzCodeService;
import com.xw.childhealth.util.ResultVOUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description:
 * @Author: y
 * @CreateDate: 2019-11-18 17:30
 * @Version: 1.0
 */
@RestController
@RequestMapping("/xzCode")
public class XzCodeController {


    @Autowired
    private XzCodeService xzCodeService;

    @PostMapping("/getXzCode")
    public ResultVO getXzCode() {
        XzCode result = xzCodeService.findByIdEquals(1);
        return ResultVOUtil.success(result);
    }

    @PostMapping("/upd")
    public ResultVO upd(@RequestBody XzCode code) {
        XzCode result = xzCodeService.findByIdEquals(code.getId());
        code.setCreateTime(result.getCreateTime());
        code.setUpdateTime(new Date());
        BeanUtils.copyProperties(code, result);
        XzCode save = xzCodeService.save(result);
        return ResultVOUtil.success(save);
    }
}

